package Lee_code;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author blh
 * @date 2024年07月02日 9:01
 */
public class Lee_179_72 {
    public String largestNumber(int[] nums) {
        int len = nums.length;
        StringBuilder sb = new StringBuilder();
        List<Integer> list = Arrays.stream(nums).boxed().collect(Collectors.toList());
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                String num1 = o1.toString();
                String num2 = o2.toString();
                StringBuilder num1num2 = new StringBuilder();
                num1num2.append(num1).append(num2);
                StringBuilder num2num1 = new StringBuilder();
                num2num1.append(num2).append(num1);
                return num2num1.toString().compareTo(num1num2.toString());
            }
        });

        for (Integer i : list) {
            sb.append(i);
        }
        if (sb.charAt(0)=='0'){
            return "0";
        }
        return sb.toString();
    }
}
